//
//  StatusModel.swift
//  Weibo-Swift
//
//  Created by law on 2018/8/30.
//  Copyright © 2018年 JKing. All rights reserved.
//

import UIKit
import Alamofire
import ObjectMapper

/// 微博数据模型
class StatusModel: BaseJsonModel {

    var id: Int64 = 0
    var text: String?
    
    override func mapping(map: Map) {
        id      <- map["id"]
        text    <- map["text"]
    }
}

// MARK: - Request
extension StatusModel {
    
    class func getHomeStatuses(completion: @escaping (WBValueResponse<[StatusModel]>) -> Void) -> Void {
        
        let url = WBURL + "2/statuses/home_timeline.json"
        
        WBNetworkManager.shared.tokenRequest(url, parameters: nil) { (response) in
            
            var statuses:[StatusModel] = []
            
//            switch response.result {
//                case .success(let json as AnyObject):
//                    
//                    let result = json["statuses"] as! NSArray
//                    statuses = Mapper<StatusModel>().mapArray(JSONArray: result as! [[String : Any]])
//                
//                case .failure(let error):
//                    print("error: \(error)")
//            }
            
            completion(WBValueResponse(value: statuses, success: response.result.isSuccess))
        }
        
    }
    
}
